
function WebEntitySelector(id) {
    this.superClase = WebSelector;
    this.superClase(id);

    this.entityName = "";
    this.foreingProperty = "";
    this.parentValue = "";
    this.propertyId = "";
    this.propertyDescription = "";

    // Funciones Publicas
    this.clone = EntitySelector_Clone;

    // Funciones Protected
    this.evalOnSelect = EntitySelector_EvalOnSelect;
    this.evalOnUnselect = EntitySelector_EvalOnUnselect;
}

function EntitySelector_Clone(newId) {
    var newSelector = new WebEntitySelector(newId);

    newSelector.width = this.width;
    newSelector.size = this.size;
    newSelector.getListFunction = this.getListFunction;
    newSelector.length = this.length;
    newSelector.cssClass = this.cssClass;
    newSelector.enabled = this.enabled;
    newSelector.active = this.active;

    newSelector.onSelect = this.onSelect;
    newSelector.onUnselect = this.onUnselect;

    newSelector.entityName = this.entityName;
    newSelector.foreingProperty = this.foreingProperty;
    newSelector.parentValue = this.parentValue;

    return newSelector;
}

function EntitySelector_RegisterRelationship(idparent, idchild) {
    Entity_Relationships[idparent] = idchild;
}

function EntitySelector_EvalOnSelect(obj) {
    if (typeof (Relationship_EvalOnChange) != "undefined")
        Relationship_EvalOnChange(this.id, this.getValue());

    eval(this.onSelect);
}

function EntitySelector_EvalOnUnselect() {
    if (typeof (Relationship_EvalOnChange) != "undefined")
        Relationship_EvalOnChange(this.id, this.getValue());

    eval(this.onUnselect);
}

function EntitySelector_GetList(selectorId, value, maxtam) {
    var mselector = Selector_Instances[selectorId];
    var propertyId = this.propertyId;
    var propertyDesc = this.propertyDescription;

    if (mselector.foreingProperty)
        EntitySelector.GetFilteredList(selectorId, mselector.entityName, value, maxtam, mselector.foreingProperty, mselector.parentValue, propertyId, propertyDesc, EntitySelector_GetListCallBack, { id: selectorId, value: value });
    else
        EntitySelector.GetList(selectorId, mselector.entityName, value, maxtam, propertyId, propertyDesc, EntitySelector_GetListCallBack, { id: selectorId, value: value });
}

function EntitySelector_GetListCallBack(response) {
    if (response.error) {
        alert(response.error)
    }
    else {
        var doc = Common.stringtoXML(response.value);
        var selectorId = response.context.id;
        var value = response.context.value;
        var selector = Selector_Get(selectorId);

        if (selector.getDescription() == value) {
            Selector_Fill(selectorId, doc);
        }
    }
}    